<?php
include_once '../samepart/header.php';
?>

<title>No.2商城-订单详情</title>

<div class="panel panel-default" style="margin: 0 auto;width: 95%;height:100%;">
    <div class="panel-heading">
        <h3 class="panel-title"><span class="glyphicon glyphicon-equalizer"></span>&nbsp;&nbsp;订单详情</h3>
    </div>
    <div class="panel-body">
        <table id="cc" cellpadding="0" cellspacing="0" align="center" width="100%"
               class="table table-striped table-bordered table-hover">
            <tr>
                <td align="right" colspan="4" style="margin-right: 40px;">
                    <a href="orderList.php" class="btn btn-danger btn-sm">返回订单列表</a>
                    &nbsp;&nbsp;
                </td>
            </tr>
        </table>
    </div>
</div>
<?php include_once '../samepart/footer.php' ?>

<script>
    console.log("getaction:"+'<?php echo $_GET['actionOrderId'] ?>')
    /**
     *
     * 拿对应商品订单地址
     * */
    function getOrderIdUaId() {
        var uaid = '';
        $.ajax({
            async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost/phalapi/public/index.php?s=App.Order.getByOrderId",
            type: "GET",
            data: {
                'orderId': '<?php echo $_GET['actionOrderId'] ?>',
            },
            dataType: "JSON",
            success: function (result) {
                uaid = result.data.info[0].uaid;
                console.log("uaid:" + uaid)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        return uaid;
    }

    /**
     *
     * 拿对应商品地址用户名名称
     * */
    function getOrderIdUaName() {
        var uaname = '';
        $.ajax({
            async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost/phalapi/public/index.php?s=App.UserAddress.getUserAddressByUaId",
            type: "GET",
            data: {
                'ua_id': getOrderIdUaId(),
            },
            dataType: "JSON",
            success: function (result) {
                uaname = result.data.info.name;

                console.log("uaname:" + uaname)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        return uaname;
    }

    /**
     *
     * 拿对应商品地址用户电话
     * */
    function getOrderIdUaPhone() {
        var uaphone = '';
        $.ajax({
            async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost/phalapi/public/index.php?s=App.UserAddress.getUserAddressByUaId",
            type: "GET",
            data: {
                'ua_id': getOrderIdUaId(),
            },
            dataType: "JSON",
            success: function (result) {
                uaphone = result.data.info.phone;

                console.log("uaname:" + uaphone)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        return uaphone;
    }

    /**
     *
     * 拿对应商品地址
     * */
    function getUserAddressInfo() {
        var uaaddress = ''
        $.ajax({
            async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost:80/phalapi/public/index.php?s=App.UserAddress.getUserAddressByUaId",
            type: "get",
            data: {
                "ua_id": getOrderIdUaId()
            },
            dataType: "JSON",
            success: function (re) {
                // var u_data = re.data.info;
                // result = u_data.detail + dd
                uaaddress = re.data.info.detail;

                console.log("result:" + uaaddress)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        return uaaddress;
    }

    /**
     *
     * 拿对应商品订单Uid
     * */
    function getOrderIdUId() {
        var uid = '';
        $.ajax({
            async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost/phalapi/public/index.php?s=App.Order.getByOrderId",
            type: "GET",
            data: {
                'orderId': '<?php echo $_GET['actionOrderId'] ?>',
            },
            dataType: "JSON",
            success: function (result) {
                uid = result.data.info[0].uid;

                console.log("uaid:" + uid)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        return uid;
    }

    /**
     *
     * 拿对应商品订单创建时间
     * */
    function getOrderIdCreateTime() {
        var createtime = '';
        $.ajax({
            async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost/phalapi/public/index.php?s=App.Order.getByOrderId",
            type: "GET",
            data: {
                'orderId': '<?php echo $_GET['actionOrderId'] ?>',
            },
            dataType: "JSON",
            success: function (result) {
                createtime = result.data.info[0].createtime;

                console.log("uaid:" + createtime)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        return createtime;
    }

    /**
     *
     * 拿对应商品订单总价
     * */
    function getOrderIdMoney() {
        var money = '';
        $.ajax({
            async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost/phalapi/public/index.php?s=App.Order.getByOrderId",
            type: "GET",
            data: {
                'orderId': '<?php echo $_GET['actionOrderId'] ?>',
            },
            dataType: "JSON",
            success: function (result) {
                money = result.data.info[0].money;

                console.log("uaid:" + money)
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        return money;
    }

    /**
     * 拿商品详情
     * */
    function inits() {
        var s = "<td align='center'>" + "商品列表:" + "</td>" + "<td colspan='3'>" +
            "<table align='center' cellpadding='0' cellspacing='0' width='100%'  class='table table-striped table-bordered table-hover'>" +
            "<tr align='center' class='info'>" +
            "<th>" + "序号" + "</th>" +
            "<th>" + "商品封面" + "</th>" +
            "<th>" + "商品名称" + "</th>" +
            "<th>" + "商品评分" + "</th>" +
            "<th>" + "商品日期" + "</th>" +
            "<th>" + "商品单价" + "</th>" +
            "<th>" + "购买数量" + "</th>" +
            "<th>" + "小计" + "</th>" + "</tr>";
        return s
    }

    function adds(gmoney, z, gname, gprice, price_url, gstar, gpubdate, gnum) {
        var s = "<tr><td>" + z + "</td><td><img src='" + price_url + "' width='30' height='30' /></td><td>" + gname + "</td><td>" + gstar + "</td><td>" + gpubdate + "</td><td>" + gprice + "</td><td>" + gnum + "</td><td>" + gmoney + "</td></tr>";

        return s
    }

    //查询全部商品
    function getGoodInfoId(goodid, gnum, gmoney, z) {
        var goodinfo = '';
        $.ajax({
            async: false,//取消异步执行，为同步执行。进而被其他方法调用
            url: "http://localhost:80/phalapi/public/index.php?s=App.Goods.getGoodInfo",
            type: "GET",
            data: {
                "good_id": goodid
            },
            dataType: "JSON",
            success: function (result) {
                var gname = result.data.info.name;
                var gprice = result.data.info.price;
                var gpicture = result.data.info.picture;
                var gstar = result.data.info.star;
                var gpubdate = result.data.info.pubdate;
                // var gpubdate = result.data.info.pubdate;
                // var user_data = result.data.info;
                // console.log("data:" + user_data[0]['id'])
                var pri_url = "../assets/fmwimages/";
                var price_url = pri_url + gpicture

                goodinfo = adds(gmoney, z, gname, gprice, price_url, gstar, gpubdate, gnum);
            },
            // $("#tb_list").html(ss);
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        return goodinfo;
    }


    /**
     * 拿商品id，并进行赋值
     **/
    //  $(function () {
    $(function () {
        $.ajax({
            url: "http://localhost/phalapi/public/index.php?s=App.OrderDetail.getOrderDetailInfoByOid",
            type: "get",
            data: {
                // "user_id":'7',
                "order_id": '<?php echo $_GET['actionOrderId'] ?>'
            },
            dataType: "JSON",
            success: function (re) {
                var u_data = re.data.info;
                console.log(u_data)
                // var a=u_data[0].createtime;
                // $("#time").html(a);
                var s = "";
                // var a = "";
                // var sm = "";
                // var sm=u_data.length;
                var ss = '';
                var z = 1;
                var d_id = '<?php echo $_GET['actionOrderId'] ?>';
                s = "<tr><td>" + "订单编号" + "</td>" + "<td>" + d_id + "</td>" +
                    "<td>" + "订单时间:" + "</td>" + "<td>" + getOrderIdCreateTime() + "</td></tr>" +
                    "<tr>" + "<td>" + "收件人:" + "</td>" + "<td id='d'>" + getOrderIdUaName() + "</td>" +
                    "<td>" + "联系电话:" + "</td>" + "<td id='dd'>" + getOrderIdUaPhone() + "</td></tr>" +
                    "<tr><td>" + "送货地址:" + "</td>" + "<td id='ddd'>" + getUserAddressInfo() + "</td>" +
                    "<td>" + "总价:" + "</td>" + "<td>" + getOrderIdMoney() + "</td></tr>" +
                    "<tr>";
                for (var i = 0; i < u_data.length; i++) {
                    // var d_id = u_data[i]['oid'];
                    var d_money = u_data[i]['money'];
                    var d_num = u_data[i]['num'];
                    var d_gid = u_data[i]['gid'];
                    var d_uaid = u_data[i]['uaid'];
                    console.log("u_data:" + d_id)
                    // var d_time = u_data[i]['createtime'];
                    ss += getGoodInfoId(d_gid, d_num, d_money, z++)
                }
                $("#cc").append(s + inits() + ss);


            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
    })

</script>